package tech.novastar.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Properties;

public class PropertiesUtil {
    private final static Logger logger =  LoggerFactory.getLogger(PropertiesUtil.class);

    /**
     * 从WEB_INF目录下获取项目配置
     */
    public static Properties getConfig() {
        Properties config = new Properties();
        try {
            JdbcUtil jdbcUtil = new JdbcUtil();
            String rootPath = jdbcUtil.getClass().getClassLoader().getResource("/").getPath();
            String configPath = Paths.get(rootPath, "..", "x.properties").toString();
            InputStream in = new FileInputStream(configPath);
            config.load(in);
        }catch (FileNotFoundException e) {
            logger.error(e.getLocalizedMessage());
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage());
        }
        return config;
    }
}
